export default (() => {
  const enumData = {
    whether: { 1: '否', 2: '是' },
    whetherOrNot: { 0: '否', 1: '是' },
    gender: { 1: '男', 2: '女' },
    readStatus: { 1: '未读', 2: '已读' },
    handleStatus: { 1: '未处理', 2: '已处理' },
    alarmHandleStatus: { '-1': '不用处理', 0: '未处理', 1: '已处理' },
    registerSource: { 1: '访客机', 2: '小程序' },
    partyUserType: { 1: '正式党员', 2: '预备党员', 3: '困难党员', 4: '发展对象', 5: '入党积极分子' },
    rewardsAndPunish: { 1: '荣誉', 2: '惩处' },
    tissueType: { 1: '物管', 2: '院/业委会', 3: '其他' },
    partyPersonState: { 1: '迁入', 2: '迁出', 3: '死亡', 4: '失联', 5: '联动中' },
    roomType: { 1: '住宅', 2: '商用', 3: '住改商', 4: '商改住' },
    doorAuthStatus: { 1: '等待授权', 2: '授权成功', 0: '授权失败' },
    teamIntegrateType: { 1: '人', 2: '车' },
    visitorVerifyWay: { 1: '身份证验证', 2: '短信验证', 3: '无访客码手机号验证' },
    isUse: { 0: '未使用', 1: '已使用' },
    isPast: { 0: '未过期', 1: '已过期' },
    isPayment: { 0: '未缴纳', 1: '已缴纳' },
    vaccination_status: { 1: '已接种第一针', 2: '已接种第二针', 3: '已接种第三针' },
    doorType: { 0: '大门', 1: '楼栋', 2: '单元', 3: '房间' },
    access_type: { 1: '进', 2: '出' },
    questionState: { 1: '进行中', 2: '计划中', 3: '已结束' },
    operate: { 1: '锁定', 2: '解锁' },
    isOnline: { true: '在线', false: '离线' },
    titleType: { 1: '单选题', 2: '多选题', 3: '填空题' },
    isOpen: { 0: '关闭', 1: '开启' },
    attendanceStatus: { 1: '正常', 2: '迟到', 3: '早退', 4: '异常' },
    attendanceType: { 1: '上勤', 2: '下勤' },
    smsSendResult: { 1: '成功', 0: '失败' },
    hotel_type: { 1: '名宿', 2: '酒店' },
    checkInStatus: { 0: '所有', 1: '在住', 2: '最新历史入住' },
    partyMemberStatus: { true: '正常', false: '停止党籍' },
    vehicleStatus: { 0: '废弃', 1: '保养', 2: '使用中', 3: '停放' },
    eventHandleState: { 1: '待处理', 2: '处理中', 3: '待办结', 4: '已办结', 5: '无效', 6: '已上报', 0: '下级处理' },
    isPush: { 0: '未发送', 1: '已发送' },
    event_level: { 1: '特急', 2: '紧急', 3: '一般' },
    warnSmallType: { 11: 'CPU', 12: '内存', 13: '硬盘', 21: 'AI能力层', 22: '成都市平台', 23: '社采平台' },
    alarmGrade: { 1: '严重', 2: '关注', 3: '一般' },
    isLive: { 0: '不常住', 1: '常住' },
    msgLevel: { 1: '一般消息', 2: '重要消息' },
    certificateNature: { 1: '有证有照', 2: '有照无证', 3: '无证无照' },
    businessStatus: { 0: '停止营业', 1: '正常营业', 2: '间断营业' },
    licenseStatus: { 0: '过期', 1: '有效', 2: '被撤销', 3: '被吊销', 4: '被撤回', 5: '注销' },
    businessFilingStatus: { 0: '注销', 1: '存活', 2: '吊销', 3: '取缔', 4: '其他减少' },
    isMarker: { 0: '未备注', 1: '已备注' },
    isLock: { 0: '未锁房', 1: '已锁房' },
    peopleType: { '01': '住户', '02': '租户', '03': '物业人员', '04': '服务人员', '05': '来访人员' },
    push_type: { 1: '数据不足', 2: '推送异常' },
    belong_type: { 1: '小区', 2: '景区' },
    is_overdue: { 0: '未超期', 1: '已超期' },
    resource: { 1: '工牌', 2: '小程序' },
    focusLevel: { 1: '一般', 2: '重点' },
  };

  function getListFromObj(obj, fields) {
    if (!obj || typeof obj !== 'object') return [];
    const opt = Object.assign({ label: 'label', value: 'value' }, fields);
    return Object.keys(obj).reduce((res, key) => {
      return [].concat(res, [{ [opt.label]: obj[key], [opt.value]: key }]);
    }, []);
  }

  return {
    setEnum(type, data) {
      enumData[type] = Object.assign({}, data);
    },
    getOriginList(type, replaceFields) {
      return [].concat(getListFromObj(enumData[type], replaceFields));
    },
    getList(type, replaceFields) {
      const all = getListFromObj({ '': '所有' }, replaceFields);
      return [].concat(all, getListFromObj(enumData[type], replaceFields));
    },
    getText(type, val) {
      return (enumData[type] && enumData[type][val]) || '';
    },
  };
})();
